<?php
class sosopage extends control
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index($recTotal=0, $recPerPage=10, $pageID=1)
    {        
        $this->app->loadClass('cpager');
    	$cpager = new cpager($recTotal, $recPerPage, $pageID);    	
		$articles = $this->sosopage->findByCpage($cpager);
        $header['title'] = $this->lang->page;
        $this->assign('header',   $header);
        $this->assign('articles', $articles);
        
        $this->assign('cpager', $cpager->get());
        $this->display();
    }
    public function cindex($rectotal=0, $recperpage=10, $pageid=1){
    	
    	$this->app->loadClass('cpager');
    	$cpager=new cpager($rectotal, $recperpage, $pageid);
    	$data = $this->sosopage->findByCpage($cpager);
    	$header['title'] = $this->lang->page;
    	$this->assign('header', $header);
    	$this->assign('articles', $data);
    	$this->assign('pager', $cpager->get());
    	$this->display('hello','index');
    }

    public function view($id)
    {
        $article = $this->hello->getInfo($id);
        $header['title'] = $this->lang->page;
        $this->assign('header',  $header);
        $this->assign('article', $article);
        $this->display();
    }

    public function del($id)
    {
        $this->hello->delArticle($id);
        header("location: " . $this->createLink($this->moduleName));
    }

    public function edit($id)
    {
        if(empty($_POST))
        {
            $header['title'] = $this->lang->page;
            $article = $this->hello->getInfo($id);
            $this->assign('header', $header);
            $this->assign('article', $article);
            $this->display();
        }
        else
        {
            $title   = filter_var($_POST['title'], FILTER_SANITIZE_STRING | FILTER_SANITIZE_MAGIC_QUOTES);
            $content = filter_var($_POST['content'], FILTER_SANITIZE_STRING | FILTER_SANITIZE_MAGIC_QUOTES);
            $id      = (int)$id;
            $this->hello->save($id, $title, $content);
            header("location: " . $this->createLink($this->moduleName));
        }
    }

    public function add()
    {
        if(empty($_POST))
        {
            $header['title'] = $this->lang->page;
            $this->assign('header', $header);
            $this->display();
        }
        else
        {
            $title   = filter_var($_POST['title'], FILTER_SANITIZE_STRING | FILTER_SANITIZE_MAGIC_QUOTES);
            $content = filter_var($_POST['content'], FILTER_SANITIZE_STRING | FILTER_SANITIZE_MAGIC_QUOTES);
            $this->hello->add($title, $content);
            header("location: " . $this->createLink($this->moduleName));
        }
    }
    
    public function search($recTotal=0, $recPerPage=10, $pageID=1){
    	
    	$this->app->loadClass('pager');
    	$pager = new pager($recTotal, $recPerPage, $pageID);
//    	var_dump($pager);
    	
		$articles = $this->hello->findByPage($pager);
        $header['title'] = $this->lang->page;
        $this->assign('header',   $header);
        $this->assign('articles', $articles);
        
        $this->assign('pager', $pager->get('right'));
        $this->display('','index');
    }
}
